﻿using System;
using fastCSharp;

namespace diantou.web.ajax.admin
{
    /// <summary>
    /// 数据库表格操作
    /// </summary>
    [fastCSharp.code.cSharp.ajax(IsPool = true)]
    class sqlTable : adminHandle<sqlTable>
    {
        /// <summary>
        /// 获取字段名称集合
        /// </summary>
        /// <param name="name"></param>
        /// <param name="identityName">自增字段名称</param>
        /// <param name="primaryKeyNames">关键字名称集合</param>
        /// <returns>字段名称集合</returns>
        public string[] GetFields(management.sqlTable.type type, string name, ref string identityName, ref string[] primaryKeyNames)
        {
            if (type == management.sqlTable.type.Exam) return diantou.examDataAccess.tcpCall.sqlTableJsonTool.getFields(name, ref identityName, ref primaryKeyNames);
            return diantou.dataAccess.tcpCall.sqlTableJsonTool.getFields(name, ref identityName, ref primaryKeyNames);
        }
        /// <summary>
        /// 根据JSON查询数据
        /// </summary>
        /// <param name="type"></param>
        /// <param name="json"></param>
        /// <param name="onReturn"></param>
        public void Query(management.sqlTable.type type, string name, string json, Action<fastCSharp.net.returnValue<keyValue<string, string>[]>> onReturn)
        {
            if (type == management.sqlTable.type.Exam) diantou.examDataAccess.tcpCall.sqlTableJsonTool.query(name, json, onReturn);
            else diantou.dataAccess.tcpCall.sqlTableJsonTool.query(name, json, onReturn);
        }
        /// <summary>
        /// 根据JSON更新数据
        /// </summary>
        /// <param name="type"></param>
        /// <param name="json"></param>
        /// <param name="values"></param>
        /// <param name="onReturn"></param>
        public void Update(management.sqlTable.type type, string name, string json, keyValue<string, string>[] values, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if (type == management.sqlTable.type.Exam) diantou.examDataAccess.tcpCall.sqlTableJsonTool.update(name, json, values, onReturn);
            else diantou.dataAccess.tcpCall.sqlTableJsonTool.update(name, json, values, onReturn);
        }
        /// <summary>
        /// 根据JSON更新数据
        /// </summary>
        /// <param name="type"></param>
        /// <param name="json"></param>
        /// <param name="onReturn"></param>
        public void Delete(management.sqlTable.type type, string name, string json, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if (type == management.sqlTable.type.Exam) diantou.examDataAccess.tcpCall.sqlTableJsonTool.delete(name, json, onReturn);
            else diantou.dataAccess.tcpCall.sqlTableJsonTool.delete(name, json, onReturn);
        }
    }
}
